﻿using Common;
using Common.DataModels;
using Microsoft.AspNetCore.Mvc;
using PLC.Domain.Dto;
using PLC.Domain.Entity;
using PLC.Domain.Models;

namespace PLC.API.Controllers
{
    [Route("api/receive-data")]
    [ApiController]
    public class TestReceiveDataController : BaseApiController
    {
        private readonly HttpHelper _httpHelper;

        public TestReceiveDataController(HttpHelper httpHelper)
        {
            _httpHelper = httpHelper;
        }
        [HttpPost]
        public async Task<MessageModel> RevceiveData(SendDataModel sendDataModel)
        {
            return Success("发送成功");
        }

        [HttpGet]
        public async Task<MessageModel> TestPost()
        {
            var list = new List<DeviceStatus>()
            {
                new DeviceStatus(16616, "12313", 5, "1313", "13313")
            };
            var model = new SendDataModel()
            {
                DeviceStatusList = list,
                DeviceBeatList = new  List<DeviceBeat>()
                {
                    new DeviceBeat(){DeviceName = "1",Time = 200},
                    new DeviceBeat(){DeviceName = "2",Time = 300}
                },
                DeviceYieldRateList = new List<YieldRate>()
                {
                    new YieldRate(){DeviceName = "1",Rate = 90.9m},
                    new YieldRate(){DeviceName = "2",Rate = 80.8m}
                }
            };
            
            var result =  await _httpHelper.PostAsync<object>("http://192.168.20.96:6790/api/device/deviceData", data: model);
            return Success();
        }
    }
}
